package com.qf.springmvc.controller;

import com.qf.springmvc.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author nk
 * @date 2022/4/29 16:56
 */
@Controller
@RequestMapping("data")
public class DataController {
    @RequestMapping("test1")
    public String test1(HttpServletRequest request, HttpSession session){
        //到request域中存数据
        request.setAttribute("name","孟云鹏");
        request.setAttribute("age",24);
        session.setAttribute("date","2022");
        return "welcome";
    }
    @RequestMapping("test2")
    public String test2(Model model) {
        // model中的数据是放到request中的
        model.addAttribute("name", "孟云鹏");
        model.addAttribute("age", 24);
        // 如果没有指定key的话，key默认就是value值的类型
        model.addAttribute("王贺");
        User user = new User();
        user.setName("王加贝");
        user.setId(11);
        model.addAttribute(user);
        return "welcome";
    }
}
